package dfs;

import java.util.*;

/**
 * @author <a href="zhaoyingling12@163.com">Zhao Simon</a>
 * @description: https://leetcode.cn/problems/subsets/?favorite=2cktkvj 78 子集
 * @date 2023/03/12
 **/
public class Subsets {


    public static void main(String[] args) {
        Solution solution = new Solution();
        Map map = new HashMap<>();
//        map.values()
        int[] nums = new int[]{1, 2, 3};
        System.out.println(solution.subsets(nums));
    }

    static class Solution {
        public List<List<Integer>> subsets(int[] nums) {
            List<List<Integer>> res = new ArrayList<>();
            res.add(new ArrayList<>());
            if (nums == null || nums.length == 0) {
                return res;
            }
            Deque<Integer> deque = new LinkedList<>();
            dfs(res, deque, 0, nums);
            return res;
        }

        private void dfs(List<List<Integer>> res, Deque<Integer> deque, int index, int[] nums) {

            if (index >= nums.length) {
                return;
            }

            for (int i = index; i < nums.length; i++) {
                deque.addLast(nums[i]);
                List<Integer> list = new ArrayList<>(deque);
                res.add(list);
                dfs(res, deque, i + 1, nums);
                deque.removeLast();
            }
        }
    }
}



